﻿@using Webdiyer.WebControls.Mvc
@using HiLand.General.Entity
@using HiLand.Utility4.MVC
@using HiLand.General
@using HiLand.Utility4.MVC.Data
@model List<ImageEntity>
@{
    ViewBag.Title = "图片列表";
    SimpleProductEntity currentProduct = this.GetPassedParam<List<ImageEntity>,SimpleProductEntity>("currentProduct");
    string returnUrl = this.GetPassedParam("returnUrl");
}
<style type="text/css">
    .modalFix
    {
        width: 650px;
    }
</style>
<h2>
    图片列表（@currentProduct.ProductName）</h2>
<div id="ItemListDIV">
    <div class="OperateArea" id="OperateAreaContainer">
        <a href="#" id="NewDisplayA" class="modalInput" productGuid="@currentProduct.ProductGuid" rel="#DetailsDisplayDIV">新建</a> | <a href="@returnUrl" target="_self">返回</a>
    </div>
    <table width="98%" class="grid">
        <tr>
            <th style="width: 150px">
                操作
            </th>
            <th style="width: 80px">
                图片名称
            </th>
            <th style="width: 80px">
                是否可用
            </th>
            <th style="width: 80px">
                是否为主图片
            </th>
            <th style="width: 60px">
                图片格式
            </th>
            
        </tr>
        @foreach (ImageEntity entity in Model)
        {
            <tr>
                <td>
                    <a href="#" class="modalInput editItme" rel="#DetailsDisplayDIV" productGuid="@currentProduct.ProductGuid" itemGuid="@entity.ImageGuid">编辑</a> | <a href="#" class="deleteItme"  itemGuid="@entity.ImageGuid">
                        删除</a>
                </td>
                <td>@entity.ImageName
                </td>
                <td>@entity.CanUsable.ToString()
                </td>
                <td>@entity.ImageIsMain.ToString()
                </td>
                <td>@entity.ImageType
                </td>
            </tr>   
        }
    </table>
    <div class="modal modalFix" id="DetailsDisplayDIV">
    </div>
       <script type="text/javascript">
           $(document).ready(function () {
               $(".modalInput").overlay({
                   mask: {
                       color: '#ebecff',
                       loadSpeed: 200,
                       opacity: 0.9
                   },
                   closeOnClick: false
               });

               var detailsUrl = '@Url.Action("ImageDetails")';
               var returnUrl = window.location;

               $("#NewDisplayA").click(function () {
                   var itemGuid = $(this).attr("productGuid");
                   $("#DetailsDisplayDIV").load($.UrlUtil(detailsUrl).concat("returnUrl", returnUrl).concat("productGuid", itemGuid).show(true));
               });

               $(".editItme").click(function () {
                   var itemGuid = $(this).attr("itemGuid");
                   var productGuid = $(this).attr("productGuid");
                   $("#DetailsDisplayDIV").load($.UrlUtil(detailsUrl).concat("returnUrl", returnUrl).concat("imageGuid", itemGuid).concat("productGuid", productGuid).show(true));
               });

               $("a.deleteItme").click(function () {
                   var result = confirm("need delete this record?");
                   if (result == true) {
                       var targetID = $(this).attr("itemGuid");
                       var url = '@Url.Action("ImageDelete")';
                       $.post(url, { imageGuid: targetID }, function (data) {
                           if (data.IsSuccessful == true) {
                               window.location.reload();
                           }
                           else {
                               alert("delete failure!");
                           }
                       });
                   }
               });

           });
    </script>
</div>


